﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SDM.ExamPlanner.BLL;
using SDM.ExamPlanner.DTO;

namespace sdm.exam.ui.ClassAdministration.TeamRegistraion
{
    /// <summary>
    /// Interaction logic for addTeamRegistration.xaml
    /// </summary>
    public partial class addTeamRegistration : UserControl
    {
        private readonly Manager<SchoolClass> _schoolClassManager = new Manager<SchoolClass>();
        private readonly Manager<Education> _educationManager = new Manager<Education>();
        private Dictionary<int, string> _dictionary;
        public addTeamRegistration()
        {
            InitializeComponent();
            populateCheckbox();
            //_schoolClassManager = new Manager<SchoolClass>();
            //_educationManager = new Manager<Education>();
        }

        private void populateCheckbox()
        {
            _dictionary = _educationManager.Find().ToDictionary(item => item.Id, item => item.Name);
            comboBoxCourse.DataContext = _dictionary.Values;
        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (datePickerEnd.SelectedDate != null && datePickerStart.SelectedDate != null)
            {
                var id = new KeyValuePair<int, string>();
                foreach (KeyValuePair<int, string> e1 in _dictionary)
                {
                    if (e1.Value == (string) comboBoxCourse.SelectedValue)
                    {
                        id = e1;
                        break;
                    }
                }
                var endTime = datePickerEnd.SelectedDate.Value;
                var startTime = datePickerStart.SelectedDate.Value;
                var schoolClass = new SchoolClass
                                      {
                                          Education = _educationManager.Find().SingleOrDefault(e2 => e2.Id == id.Key),
                                          EndDate = new DateTime(endTime.Year,endTime.Month,endTime.Day),
                                          StartDate = new DateTime(startTime.Year, startTime.Month, startTime.Day),
                                          Name = txtClassName.Text
                                      };
                _schoolClassManager.Save(schoolClass);
                MessageBox.Show("School class is added!");
            }
                //SemesterClassManager.AddNewSemesterClass(txtClassName.Text, datePickerStart.SelectedDate.Value, datePickerEnd.SelectedDate.Value, comboBoxCourse.SelectedItem);
        }
    }
}
